﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BPC.Magic8Ball.MSTest
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class Ball
    {

        Magic8Ball.Ball ball;
        string answer;

        public Ball()
        {
            //Arrange
            ball = new BPC.Magic8Ball.Ball();
            answer = "";
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void ShouldReturnAnAnswerWhenAskedQuestion()
        {

            //Act
            answer = ball.AskQuestion("Will the work?");

            //Assert
            Assert.IsNotNull(answer);
        }

        [TestMethod]
        public void ShouldReturnAValidAnswerWhenAskedQuestion()
        {

            //Act
            answer = ball.AskQuestion("A different question");

            //Assert
            Assert.IsTrue(ball.Answers.Contains(answer));
        }

        [TestMethod]
        public void ShouldReturnAnswerFromCustomAnswer()
        {

            //Arrange
            ball.Answers = new List<string>() { "Custom Answer" };

            //Act
            answer = ball.AskQuestion("Give me a custome answer");

            //Assert
            Assert.AreEqual("Custom Answer", answer);
        }

        [TestMethod]
        public void ShouldReturnAMixOfAnswerFromCustomQuestions()
        {
            //Arrange
            ball.Answers = new List<string>() { "One", "Two", "Three" };
            int one = 0;
            int two = 0;
            int three = 0;

            //Act
            for (int i = 0; i < 100000; i++)
            {
                answer = ball.AskQuestion(i.ToString());
                if (answer == "One") one++;
                if (answer == "Two") two++;
                if (answer == "Three") three++;
            }

            //Assert
            Assert.AreNotEqual(0, one, "One");
            Assert.AreNotEqual(0, two, "Two");
            Assert.AreNotEqual(0, three, "Three");
        }

    }
}
